/*
 * ConnectionGeneralInfoPanel.java
 *
 * Created on June 29, 2008, 3:09 PM
 */

package pl.edu.agh.ssm.monitor.gui;

import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import pl.edu.agh.ssm.monitor.data.SessionConnection;

/**
 *
 * @author  aneezka
 */
@SuppressWarnings("serial")
public class ConnectionGeneralInfoPanel extends javax.swing.JPanel implements UpdatePanel {
    
    /** Creates new form ConnectionGeneralInfoPanel */
    public ConnectionGeneralInfoPanel(SessionConnection connection) {
        this.connection = connection;
        initComponents();
    }
    
    @Override
    public String getName() {
        return "General Info";
    }
    
    public void update() {
        senderLabel.setText(connection.getSender().getAddress().getHostAddress());
        receiverLabel.setText(connection.getReceiver().getAddress().getHostAddress());
        mediaTypeLabel.setText("" + connection.getMediaDesc().getMediaType());
        mediaNameLabel.setText("" + connection.getMediaDesc().getMediaName());
        mediaFreqLabel.setText("" + connection.getMediaDesc().getMediaFreq() + " [Hz]");
        lastReportLabel.setText("" + connection.getLastReceiverReportTime() + 
        		" (" + new Date(connection.getLastReceiverReportTime())+ ")");
        lastRtpSeqNumLabel.setText("" + connection.getLastRtpPacket().getLastPacketSequenceNumber());
        lastRtpTimestampLabel.setText("" + connection.getLastRtpPacket().getLastPacketTimeStamp());
        for (UpdatePanelListener l : listeners) {
            l.panelUpdated(this);
        }
    }
    
    public void remove() {
        for (UpdatePanelListener l : listeners) {
            l.panelRemoved(this);
        }
    }

    public void addListener(UpdatePanelListener listener) {
        listeners.add(listener);
    }

    public void removeListener(UpdatePanelListener listener) {
        listeners.remove(listener);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        senderLabel = new javax.swing.JLabel();
        receiverLabel = new javax.swing.JLabel();
        mediaTypeLabel = new javax.swing.JLabel();
        mediaNameLabel = new javax.swing.JLabel();
        mediaFreqLabel = new javax.swing.JLabel();
        lastReportLabel = new javax.swing.JLabel();
        lastRtpSeqNumLabel = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        lastRtpTimestampLabel = new javax.swing.JLabel();

        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(pl.edu.agh.ssm.monitor.SessionMonitorApp.class).getContext().getResourceMap(ConnectionGeneralInfoPanel.class);
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        senderLabel.setText(resourceMap.getString("senderLabel.text")); // NOI18N
        senderLabel.setName("senderLabel"); // NOI18N

        receiverLabel.setText(resourceMap.getString("receiverLabel.text")); // NOI18N
        receiverLabel.setName("receiverLabel"); // NOI18N

        mediaTypeLabel.setText(resourceMap.getString("mediaTypeLabel.text")); // NOI18N
        mediaTypeLabel.setName("mediaTypeLabel"); // NOI18N

        mediaNameLabel.setText(resourceMap.getString("mediaNameLabel.text")); // NOI18N
        mediaNameLabel.setName("mediaNameLabel"); // NOI18N

        mediaFreqLabel.setText(resourceMap.getString("mediaFreqLabel.text")); // NOI18N
        mediaFreqLabel.setName("mediaFreqLabel"); // NOI18N

        lastReportLabel.setText(resourceMap.getString("lastReportLabel.text")); // NOI18N
        lastReportLabel.setName("lastReportLabel"); // NOI18N

        lastRtpSeqNumLabel.setText(resourceMap.getString("lastRtpSeqNumLabel.text")); // NOI18N
        lastRtpSeqNumLabel.setName("lastRtpSeqNumLabel"); // NOI18N

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        lastRtpTimestampLabel.setText(resourceMap.getString("lastRtpTimestampLabel.text")); // NOI18N
        lastRtpTimestampLabel.setName("lastRtpTimestampLabel"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6)
                    .addComponent(jLabel7)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lastRtpSeqNumLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 238, Short.MAX_VALUE)
                    .addComponent(lastReportLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 238, Short.MAX_VALUE)
                    .addComponent(mediaFreqLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 238, Short.MAX_VALUE)
                    .addComponent(mediaNameLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 238, Short.MAX_VALUE)
                    .addComponent(mediaTypeLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 238, Short.MAX_VALUE)
                    .addComponent(receiverLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 238, Short.MAX_VALUE)
                    .addComponent(senderLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 238, Short.MAX_VALUE)
                    .addComponent(lastRtpTimestampLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 238, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(senderLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(receiverLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(mediaTypeLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(mediaNameLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(mediaFreqLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(lastReportLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lastRtpSeqNumLabel)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(lastRtpTimestampLabel))
                .addContainerGap(16, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents
    
    private SessionConnection connection;
    private List<UpdatePanelListener> listeners = new LinkedList<UpdatePanelListener>(); 
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel lastReportLabel;
    private javax.swing.JLabel lastRtpSeqNumLabel;
    private javax.swing.JLabel lastRtpTimestampLabel;
    private javax.swing.JLabel mediaFreqLabel;
    private javax.swing.JLabel mediaNameLabel;
    private javax.swing.JLabel mediaTypeLabel;
    private javax.swing.JLabel receiverLabel;
    private javax.swing.JLabel senderLabel;
    // End of variables declaration//GEN-END:variables
    
}
